package ioperation;

import book.BookList;

import java.util.Scanner;

public class BorrowOperation implements IOperations{
    @Override
    public void work(BookList bookList) {
        System.out.println("--------借阅图书--------");
        System.out.println("请输入你要借阅的图书的名字：");
        Scanner scanner = new Scanner(System.in);
        String name = scanner.nextLine();
        int i = 0;
        int currentSize = bookList.getUsedSize();
        //首先要看书架上是否有你想要借阅的书
        for (i = 0; i < currentSize; i++) {
            if(bookList.getBook(i).getName().equals(name) && bookList.getBook(i).isBorrowed() == false) {
                System.out.println("有你想要借阅的书!!!");
                break;
            }
        }
        //没有找到你要借阅的书
        if(i == bookList.getBooks().length) {
            System.out.println("没有找到你想要借阅的书!!!");
            return;
        }
        if(bookList.getBook(i).isBorrowed() == true) {
            System.out.println("你要借阅的图已经被借走了");
            return;
        }

        bookList.getBook(i).setBorrowed(true);
        System.out.println("借阅成功!!!");
    }
}
